home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb / foo / m-sun2.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-28  |  16.2 KB  |  463 lines

  1. /* Parameters for execution on a Sun, for GDB, the GNU debugger.
  2.    Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifndef sun2
  21. #define sun2
  22. #endif
  23.  
  24. /* Define the bit, byte, and word ordering of the machine.  */
  25. #define BITS_BIG_ENDIAN
  26. #define BYTES_BIG_ENDIAN
  27. #define WORDS_BIG_ENDIAN
  28.  
  29. /* Define this if the C compiler puts an underscore at the front
  30.    of external names before giving them to the linker.  */
  31.  
  32. #define NAMES_HAVE_UNDERSCORE
  33.  
  34. /* Debugger information will be in DBX format.  */
  35.  
  36. #define READ_DBX_FORMAT
  37.  
  38. /* Offset from address of function to start of its code.
  39.    Zero on most machines.  */
  40.  
  41. #define FUNCTION_START_OFFSET 0
  42.  
  43. /* Advance PC across any function entry prologue instructions
  44.    to reach some "real" code.  */
  45.  
  46. #define SKIP_PROLOGUE(pc)   \
  47. { register int op = read_memory_integer (pc, 2);    \
  48.   if (op == 0047126)                \
  49.     pc += 4;   /* Skip link #word */            \
  50.   else if (op == 0044016)            \
  51.     pc += 6;   /* Skip link #long */            \
  52. }
  53.  
  54. /* Immediately after a function call, return the saved pc.
  55.    Can't go through the frames for this because on some machines
  56.    the new frame is not set up until the new function executes
  57.    some instructions.  */
  58.  
  59. #define SAVED_PC_AFTER_CALL(frame) \
  60. read_memory_integer (read_register (SP_REGNUM), 4)
  61.  
  62. /* This is the amount to subtract from u.u_ar0
  63.    to get the offset in the core file of the register values.  */
  64.  
  65. #define KERNEL_U_ADDR 0x2800
  66.  
  67. /* Address of end of stack space.  */
  68.  
  69. #define STACK_END_ADDR 0x1000000
  70.  
  71. /* Stack grows downward.  */
  72.  
  73. #define INNER_THAN <
  74.  
  75. /* Sequence of bytes for breakpoint instruction.  */
  76.  
  77. #define BREAKPOINT {0x4e, 0x4f}
  78.  
  79. /* Amount PC must be decremented by after a breakpoint.
  80.    This is often the number of bytes in BREAKPOINT
  81.    but not always.  */
  82.  
  83. #define DECR_PC_AFTER_BREAK 2
  84.  
  85. /* Nonzero if instruction at PC is a return instruction.  */
  86.  
  87. #define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 2) == 0x4e75)
  88.  
  89. /* Return 1 if P points to an invalid floating point value.  */
  90.  
  91. #define INVALID_FLOAT(p, len) 0   /* Just a first guess; not checked */
  92.  
  93. /* Largest integer type */
  94. #define LONGEST long
  95.  
  96. /* Name of the builtin type for the LONGEST type above. */
  97. #define BUILTIN_TYPE_LONGEST builtin_type_long
  98.  
  99. /* Say how long registers are.  */
  100.  
  101. #define REGISTER_TYPE long
  102.  
  103. /* Number of machine registers */
  104.  
  105. #define NUM_REGS 18
  106.  
  107. /* Number that are really general registers */
  108.  
  109. #define NUM_GENERAL_REGS 16
  110.  
  111. /* Initializer for an array of names of registers.
  112.    There should be NUM_REGS strings in this initializer.  */
  113.  
  114. #define REGISTER_NAMES {"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", "ps", "pc"}
  115.  
  116. /* Register numbers of various important registers.
  117.    Note that some of these values are "real" register numbers,
  118.    and correspond to the general registers of the machine,
  119.    and some are "phony" register numbers which are too large
  120.    to be actual register numbers as far as the user is concerned
  121.    but do serve to get the desired values when passed to read_register.  */
  122.  
  123. #define FP_REGNUM 14        /* Contains address of executing stack frame */
  124. #define SP_REGNUM 15        /* Contains address of top of stack */
  125. #define PS_REGNUM 16        /* Contains processor status */
  126. #define PC_REGNUM 17        /* Contains program counter */
  127.  
  128. /* Total amount of space needed to store our copies of the machine's
  129.    register state, the array `registers'.  */
  130. #define REGISTER_BYTES (16*4+8)
  131.  
  132. /* Index within `registers' of the first byte of the space for
  133.    register N.  */
  134.  
  135. #define REGISTER_BYTE(N)  ((N) * 4)
  136.  
  137. /* Number of bytes of storage in the actual machine representation
  138.    for register N.  On the 68000, all regs are 4 bytes.  */
  139.  
  140. #define REGISTER_RAW_SIZE(N) 4
  141.  
  142. /* Number of bytes of storage in the program's representation
  143.    for register N.  On the 68000, all regs are 4 bytes.  */
  144.  
  145. #define REGISTER_VIRTUAL_SIZE(N) 4
  146.  
  147. /* Largest value REGISTER_RAW_SIZE can have.  */
  148.  
  149. #define MAX_REGISTER_RAW_SIZE 4
  150.  
  151. /* Largest value REGISTER_VIRTUAL_SIZE can have.  */
  152.  
  153. #define MAX_REGISTER_VIRTUAL_SIZE 4
  154.  
  155. /* Nonzero if register N requires conversion
  156.    from raw format to virtual format.  */
  157.  
  158. #define REGISTER_CONVERTIBLE(N) 0
  159.  
  160. /* Convert data from raw format for register REGNUM
  161.    to virtual format for register REGNUM.  */
  162.  
  163. #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO)  bcopy ((FROM), (TO), 4);
  164.  
  165. /* Convert data from virtual format for register REGNUM
  166.    to raw format for register REGNUM.  */
  167.  
  168. #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO)  bcopy ((FROM), (TO), 4);
  169.  
  170. /* Return the GDB type object for the "standard" data type
  171.    of data in register N.  */
  172.  
  173. #define REGISTER_VIRTUAL_TYPE(N)  builtin_type_int
  174.  
  175. /* Store the address of the place in which to copy the structure the
  176.    subroutine will return.  This is called from call_function. */
  177.  
  178. #define STORE_STRUCT_RETURN(ADDR, SP) \
  179.   { write_register (9, (ADDR)); }
  180.  
  181. /* Extract from an array REGBUF containing the (raw) register state
  182.    a function return value of type TYPE, and copy that, in virtual format,
  183.    into VALBUF.  */
  184.  
  185. #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
  186.   bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE))
  187.  
  188. /* Write into appropriate registers a function return value
  189.    of type TYPE, given in virtual format.  */
  190.  
  191. #define STORE_RETURN_VALUE(TYPE,VALBUF) \
  192.   write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
  193.  
  194. /* Extract from an array REGBUF containing the (raw) register state
  195.    the address in which a function should return its structure value,
  196.    as a CORE_ADDR (or an expression that can be used as one).  */
  197.  
  198. #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
  199.  
  200. /* Enable use of alternate code to read and write registers.  */
  201.  
  202. #define NEW_SUN_PTRACE
  203.  
  204. /* Enable use of alternate code for Sun's format of core dump file.  */
  205.  
  206. #define NEW_SUN_CORE
  207.  
  208. /* Do implement the attach and detach commands.  */
  209.  
  210. #define ATTACH_DETACH
  211.  
  212. /* This is a piece of magic that is given a register number REGNO
  213.    and as BLOCKEND the address in the system of the end of the user structure
  214.    and stores in ADDR the address in the kernel or core dump
  215.    of that register.  */
  216.  
  217. #define REGISTER_U_ADDR(addr, blockend, regno)        \
  218. { addr = blockend + regno * 4; }
  219.  
  220. /* Describe the pointer in each stack frame to the previous stack frame
  221.    (its caller).  */
  222.  
  223. /* FRAME_CHAIN takes a frame's nominal address
  224.    and produces the frame's chain-pointer.
  225.  
  226.    FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
  227.    and produces the nominal address of the caller frame.
  228.  
  229.    However, if FRAME_CHAIN_VALID returns zero,
  230.    it means the given frame is the outermost one and has no caller.
  231.    In that case, FRAME_CHAIN_COMBINE is not used.  */
  232.  
  233. /* In the case of the Sun, the frame's nominal address
  234.    is the address of a 4-byte word containing the calling frame's address.  */
  235.  
  236. #define FRAME_CHAIN(thisframe)  \
  237.   (outside_startup_file ((thisframe)->pc) ? \
  238.    read_memory_integer ((thisframe)->frame, 4) :\
  239.    0)
  240.  
  241. #define FRAME_CHAIN_VALID(chain, thisframe) \
  242.   (chain != 0 && (outside_startup_file (FRAME_SAVED_PC (thisframe))))
  243.  
  244. #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
  245.  
  246. /* Define other aspects of the stack frame.  */
  247.  
  248. /* A macro that tells us whether the function invocation represented
  249.    by FI does not have a frame on the stack associated with it.  If it
  250.    does not, FRAMELESS is set to 1, else 0.  */
  251. #define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \
  252.   FRAMELESS_LOOK_FOR_PROLOGUE(FI, FRAMELESS)
  253.  
  254. #define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4))
  255.  
  256. #define FRAME_ARGS_ADDRESS(fi) ((fi)->frame)
  257.  
  258. #define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame)
  259.  
  260. /* Set VAL to the number of args passed to frame described by FI.
  261.    Can set VAL to -1, meaning no way to tell.  */
  262.  
  263. /* We can't tell how many args there are
  264.    now that the C compiler delays popping them.  */
  265. #define FRAME_NUM_ARGS(val,fi) (val = -1)
  266.  
  267. #if 0
  268. #define FRAME_NUM_ARGS(val, fi)  \
  269. { register CORE_ADDR pc = FRAME_SAVED_PC (fi);        \
  270.   register int insn = 0177777 & read_memory_integer (pc, 2);    \
  271.   val = 0;                            \
  272.   if (insn == 0047757 || insn == 0157374)  /* lea W(sp),sp or addaw #W,sp */ \
  273.     val = read_memory_integer (pc + 2, 2);            \
  274.   else if ((insn & 0170777) == 0050217 /* addql #N, sp */    \
  275.        || (insn & 0170777) == 0050117)  /* addqw */        \
  276.     { val = (insn >> 9) & 7; if (val == 0) val = 8; }        \
  277.   else if (insn == 0157774) /* addal #WW, sp */            \
  278.     val = read_memory_integer (pc + 2, 4);            \
  279.   val >>= 2; }
  280. #endif
  281.  
  282. /* Return number of bytes at start of arglist that are not really args.  */
  283.  
  284. #define FRAME_ARGS_SKIP 8
  285.  
  286. /* Put here the code to store, into a struct frame_saved_regs,
  287.    the addresses of the saved registers of frame described by FRAME_INFO.
  288.    This includes special registers such as pc and fp saved in special
  289.    ways in the stack frame.  sp is even more special:
  290.    the address we return for it IS the sp for the next frame.  */
  291.  
  292. #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs)        \
  293. { register int regnum;                            \
  294.   register int regmask;                            \
  295.   register CORE_ADDR next_addr;                        \
  296.   register CORE_ADDR pc;                        \
  297.   bzero (&frame_saved_regs, sizeof frame_saved_regs);            \
  298.   if ((frame_info)->pc >= (frame_info)->frame - CALL_DUMMY_LENGTH - FP_REGNUM*4 - 4 \
  299.       && (frame_info)->pc <= (frame_info)->frame)                \
  300.     { next_addr = (frame_info)->frame;                    \
  301.       pc = (frame_info)->frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 4; }\
  302.   else                                   \
  303.     { pc = get_pc_function_start ((frame_info)->pc);             \
  304.       /* Verify we have a link a6 instruction next;            \
  305.      if not we lose.  If we win, find the address above the saved   \
  306.      regs using the amount of storage from the link instruction.  */\
  307.       if (044016 == read_memory_integer (pc, 2))            \
  308.     next_addr = (frame_info)->frame + read_memory_integer (pc += 2, 4), pc+=4; \
  309.       else if (047126 == read_memory_integer (pc, 2))            \
  310.     next_addr = (frame_info)->frame + read_memory_integer (pc += 2, 2), pc+=2; \
  311.       else goto lose;                            \
  312.       /* If have an addal #-n, sp next, adjust next_addr.  */        \
  313.       if ((0177777 & read_memory_integer (pc, 2)) == 0157774)        \
  314.     next_addr += read_memory_integer (pc += 2, 4), pc += 4;        \
  315.     }                                    \
  316.   /* next should be a moveml to (sp) or -(sp) or a movl r,-(sp) */    \
  317.   regmask = read_memory_integer (pc + 2, 2);                \
  318.   if (0044327 == read_memory_integer (pc, 2))                \
  319.     { pc += 4; /* Regmask's low bit is for register 0, the first written */ \
  320.       for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)        \
  321.     if (regmask & 1)                        \
  322.           (frame_saved_regs).regs[regnum] = (next_addr += 4) - 4; }    \
  323.   else if (0044347 == read_memory_integer (pc, 2))            \
  324.     { pc += 4; /* Regmask's low bit is for register 15, the first pushed */ \
  325.       for (regnum = 15; regnum >= 0; regnum--, regmask >>= 1)        \
  326.     if (regmask & 1)                        \
  327.           (frame_saved_regs).regs[regnum] = (next_addr -= 4); }        \
  328.   else if (0x2f00 == 0xfff0 & read_memory_integer (pc, 2))        \
  329.     { regnum = 0xf & read_memory_integer (pc, 2); pc += 2;        \
  330.       (frame_saved_regs).regs[regnum] = (next_addr -= 4); }        \
  331.   /* clrw -(sp); movw ccr,-(sp) may follow.  */                \
  332.   if (0x426742e7 == read_memory_integer (pc, 4))            \
  333.     (frame_saved_regs).regs[PS_REGNUM] = (next_addr -= 4);        \
  334.   lose: ;                                \
  335.   (frame_saved_regs).regs[SP_REGNUM] = (frame_info)->frame + 8;        \
  336.   (frame_saved_regs).regs[FP_REGNUM] = (frame_info)->frame;        \
  337.   (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 4;        \
  338. }
  339.  
  340. /* Things needed for making the inferior call functions.  */
  341.  
  342. /* Push an empty stack frame, to record the current PC, etc.  */
  343.  
  344. #define PUSH_DUMMY_FRAME \
  345. { register CORE_ADDR sp = read_register (SP_REGNUM);\
  346.   register int regnum;                    \
  347.   sp = push_word (sp, read_register (PC_REGNUM));   \
  348.   sp = push_word (sp, read_register (FP_REGNUM));   \
  349.   write_register (FP_REGNUM, sp);            \
  350.   for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)  \
  351.     sp = push_word (sp, read_register (regnum));    \
  352.   sp = push_word (sp, read_register (PS_REGNUM));   \
  353.   write_register (SP_REGNUM, sp);  }
  354.  
  355. /* Discard from the stack the innermost frame, restoring all registers.  */
  356.  
  357. #define POP_FRAME  \
  358. { register FRAME frame = get_current_frame ();             \
  359.   register CORE_ADDR fp;                     \
  360.   register int regnum;                         \
  361.   struct frame_saved_regs fsr;                     \
  362.   struct frame_info *fi;                         \
  363.   fi = get_frame_info (frame);                     \
  364.   fp = fi->frame;                         \
  365.   get_frame_saved_regs (fi, &fsr);                 \
  366.   for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)         \
  367.     if (fsr.regs[regnum])                     \
  368.       write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \
  369.   if (fsr.regs[PS_REGNUM])                     \
  370.     write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4)); \
  371.   write_register (FP_REGNUM, read_memory_integer (fp, 4));     \
  372.   write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));   \
  373.   write_register (SP_REGNUM, fp + 8);                 \
  374.   flush_cached_frames ();                     \
  375.   set_current_frame ( create_new_frame (read_register (FP_REGNUM),\
  376.                     read_pc ())); }
  377.  
  378. /* This sequence of words is the instructions
  379.      moveml 0xfffc,-(sp)
  380.      clrw -(sp)
  381.      movew ccr,-(sp)
  382.      /..* The arguments are pushed at this point by GDB;
  383.     no code is needed in the dummy for this.
  384.     The CALL_DUMMY_START_OFFSET gives the position of
  385.     the following jsr instruction.  *../
  386.      jsr @#32323232
  387.      addl #69696969,sp
  388.      bpt
  389.      nop
  390. Note this is 24 bytes.
  391. We actually start executing at the jsr, since the pushing of the
  392. registers is done by PUSH_DUMMY_FRAME.  If this were real code,
  393. the arguments for the function called by the jsr would be pushed
  394. between the moveml and the jsr, and we could allow it to execute through.
  395. But the arguments have to be pushed by GDB after the PUSH_DUMMY_FRAME is done,
  396. and we cannot allow the moveml to push the registers again lest they be
  397. taken for the arguments.  */
  398.  
  399. #define CALL_DUMMY {0x48e7fffc, 0x426742e7, 0x4eb93232, 0x3232dffc, 0x69696969, 0x4e4f4e71}
  400.  
  401. #define CALL_DUMMY_LENGTH 24
  402.  
  403. #define CALL_DUMMY_START_OFFSET 8
  404.  
  405. /* Insert the specified number of args and function address
  406.    into a call sequence of the above form stored at DUMMYNAME.  */
  407.  
  408. #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, type)     \
  409. { *(int *)((char *) dummyname + 16) = nargs * 4;  \
  410.   *(int *)((char *) dummyname + 10) = fun; }
  411.  
  412. /* Interface definitions for kernel debugger KDB.  */
  413.  
  414. /* Map machine fault codes into signal numbers.
  415.    First subtract 0, divide by 4, then index in a table.
  416.    Faults for which the entry in this table is 0
  417.    are not handled by KDB; the program's own trap handler
  418.    gets to handle then.  */
  419.  
  420. #define FAULT_CODE_ORIGIN 0
  421. #define FAULT_CODE_UNITS 4
  422. #define FAULT_TABLE    \
  423. { 0, 0, 0, 0, SIGTRAP, 0, 0, 0, \
  424.   0, SIGTRAP, 0, 0, 0, 0, 0, SIGKILL, \
  425.   0, 0, 0, 0, 0, 0, 0, 0, \
  426.   SIGILL }
  427.  
  428. /* Start running with a stack stretching from BEG to END.
  429.    BEG and END should be symbols meaningful to the assembler.
  430.    This is used only for kdb.  */
  431.  
  432. #define INIT_STACK(beg, end)  \
  433. { asm (".globl end");         \
  434.   asm ("movel $ end, sp");      \
  435.   asm ("clrl fp"); }
  436.  
  437. /* Push the frame pointer register on the stack.  */
  438. #define PUSH_FRAME_PTR        \
  439.   asm ("movel fp, -(sp)");
  440.  
  441. /* Copy the top-of-stack to the frame pointer register.  */
  442. #define POP_FRAME_PTR  \
  443.   asm ("movl (sp), fp");
  444.  
  445. /* After KDB is entered by a fault, push all registers
  446.    that GDB thinks about (all NUM_REGS of them),
  447.    so that they appear in order of ascending GDB register number.
  448.    The fault code will be on the stack beyond the last register.  */
  449.  
  450. #define PUSH_REGISTERS        \
  451. { asm ("clrw -(sp)");          \
  452.   asm ("pea 10(sp)");          \
  453.   asm ("movem $ 0xfffe,-(sp)"); }
  454.  
  455. /* Assuming the registers (including processor status) have been
  456.    pushed on the stack in order of ascending GDB register number,
  457.    restore them and return to the address in the saved PC register.  */
  458.  
  459. #define POP_REGISTERS          \
  460. { asm ("subil $8,28(sp)");     \
  461.   asm ("movem (sp),$ 0xffff"); \
  462.   asm ("rte"); }
  463.